package cn.springBoot.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import cn.springBoot.entity.User;
import cn.springBoot.service.UserService;
import cn.springBoot.util.FileUploadUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ljx
 * @since 2020-01-16
 */
@RestController
@RequestMapping("/user")
@Api(value = "用户controller", tags = {"用户操作接口"})
@AllArgsConstructor
public class UserController {

    private final static Logger logger = LoggerFactory.getLogger(SchoolController.class);

    private UserService userService;

    // private RedisUtil wxredisUtil;

    @GetMapping("/getAll")
    @ApiOperation(value = "获取全部user接口", response = User.class, responseContainer = "list")
    public List<User> findAll() {

        logger.info("getAll");

        return userService.selectList(null);

    }

    @GetMapping("/getById")
    @ApiOperation(value = "根据id获取user", response = User.class)
    public User getById(@RequestParam int id) {

        logger.info("getAll");
        // wxredisUtil.save("111", "1111");
        return userService.selectByIda(id);

    }

    @GetMapping("/update")
    @ApiOperation(value = "修改user", response = User.class)
    public User update(User user) {

        logger.info("update");

        return userService.updateUser(user);

    }

    @GetMapping("/del")
    @ApiOperation(value = "删除")
    public String deleteEmp(Integer id) {
        logger.info("del");

        return userService.delUser(id);
    }

    @PostMapping(value = "/fileUpload")
    @ApiOperation(value = "图片上传")
    public String fileUpload(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request) {

        return FileUploadUtil.fileUpLoad(file);
    }

}
